package com.lw.sbdemo2.common.startup;

import com.google.common.hash.BloomFilter;
import com.lw.sbdemo2.common.cache.CacheHandle;
import com.lw.sbdemo2.common.utils.IdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import java.util.concurrent.atomic.AtomicInteger;

/**
 * <p>标题: CommandLineRunner启动加载</p>
 * <p>描述: </p>
 * <p>版权: Copyright (c) 2018</p>
 * <p>公司: 智业软件</p>
 *
 * @author LinWang
 * @date 2018-06-21 14:04
 */
@Component
@Order(1)
@Slf4j
public class MyApplicationRunner implements ApplicationRunner {

    private static final int INSERTIONS = 10000;

    private static final int MULTIPLE = 2;

    /**
     * 布隆过滤器
     */
    public static BloomFilter<String> bloomFilter;

    @Override
    public void run(ApplicationArguments args) throws Exception {
        log.info("MyApplicationRunner 启动加载，author：{}", args.getOptionValues("author"));

        //执行业务逻辑
        doBiz();
    }

    /**
     * 执行业务逻辑
     */
    private void doBiz() {

        //订单NUM
        AtomicInteger tempNum = CacheHandle.getOrderNum();
        if (tempNum != null) {
            IdUtils.atomicInteger = tempNum;
        } else {
            CacheHandle.setOrderNum(new AtomicInteger(200000));
            IdUtils.atomicInteger = new AtomicInteger(200000);
        }
    }
}
